<template>
  <router-view />
  <van-tabbar v-model="active">
      <van-tabbar-item
        v-for="info of tabbars"
        :key="info.path"
        :icon="info.icon"
        :to="info.path"
      >
        {{info.label}}
      </van-tabbar-item>
  </van-tabbar>
</template>
<script lang="ts">
import { defineComponent, ref, watch } from 'vue'
import {useRoute} from 'vue-router'
const tabbars = [
  {
    label: '首页',
    path: '/',
    icon: 'home-o'
  },
  {
    label: '统计',
    path: '/about',
    icon: 'search'
  },
  {
    label: '个人中心',
    path: '/my',
    icon: 'friends-o'
  },
]
export default defineComponent({
  name: 'App',
  setup() {
    const active = ref(0);
    const route = useRoute();
    watch(route, (route, preCount) => {
      const idx = tabbars.findIndex(item => item.path === route.path)
      if (idx > -1) {
        active.value = idx;
      }
    })
    return {
      active,
      tabbars
    }
  },
})
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
